# 1. 建文件夹（如已存在则跳过）
$excelDir = "$env:USERPROFILE\Desktop\excel"
if (!(Test-Path $excelDir)) {
    New-Item -ItemType Directory -Path $excelDir | Out-Null
}

# 2. 强制关闭所有 Excel/WPS/ET 进程，防止占用
Get-Process | Where-Object {
    $_.ProcessName -match "excel|et|wps"
} | Stop-Process -Force -ErrorAction SilentlyContinue

# 3. 移动桌面（含子目录）内所有 *.xls* 文件，跳过已位于 excel 内的
Get-ChildItem -Path "$env:USERPROFILE\Desktop" -Recurse -Include *.xls*, *.xlsx |
    Where-Object { $_.DirectoryName -notlike "*\excel*" } |
    ForEach-Object {
        $dest = Join-Path $excelDir $_.Name
        # 如目标重名，直接覆盖
        Move-Item -Path $_.FullName -Destination $dest -Force -ErrorAction SilentlyContinue
    }

Write-Host "Excel 文件已收拢到桌面 excel 文件夹。"
